#include <bits/stdc++.h>

using namespace std;
#define int long long
const int N = 1e4 + 10, mod = 1e9 + 7;
int dp[N];
char s[N], s1[N];
vector<int> a[30];
void solve() {
	scanf("%s %s", s + 1, s1 + 1);
	memset(dp, 0, sizeof dp);
	dp[0] = 1;
	for (int i = 0; i <= 30; i++)a[i].clear();
	for (int i = (int)strlen(s1 + 1); i >= 1 ; i--)a[s1[i] - 'a'].push_back(i);
	for (int i = 1; i <= (int)strlen(s + 1); i++) {
		for (auto j : a[s[i] - 'a'])dp[j] += dp[j - 1], dp[j] %= mod;
	}
	cout << dp[strlen(s1 + 1)] << endl;
}
signed main() {
	int t;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}
